<?php
namespace App\Http\Controllers\System;

use App\Http\Controllers\Controller;
use App\Http\Requests\System\Message\ListsRequest;
use App\Repositories\System\MessageRepository;

class MessageController extends Controller{

    public function list(ListsRequest $request, MessageRepository $repository)
    {
        $uid = $request->get("uid");
        $page = $request->get("page", 0);
        $limit = $request->get("limit", 15);
        $models = $repository->getMessageList($uid, ['id', 'title', 'status'], $page, $limit);
        $pages = @$models->toArray()?:[];
        if ($pages) return success($pages);
        return failed("没有消息");
    }

    public function detail(MessageRepository $repository, $id)
    {
        $detail = $repository->getMessageDetail($id);
        return success($detail->toArray());
    }

    public function sign(MessageRepository $repository, $uid)
    {
        $repository->markedRead($uid);
        success([]);
    }

}